//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using CommunityServer;
using CommunityServer.Components;
using CommunityServer.Controls;
using CommunityServer.Files.Components;

namespace CommunityServer.Files.Controls
{
	/// <summary>
	/// Base class for skinned gallery controls.
	/// </summary>
	public abstract class FileGalleryTemplatedWebControl : TemplatedWebControl
	{
		private User _currentUser = null;
		private Folder _currentFolder = null;
		private PostCategory _currentCategory = null;
		private Entry _currentEntry = null;
		CSContext csContext = CSContext.Current;

		public FileGalleryTemplatedWebControl():base()
		{
			_currentUser = Users.GetUser(true);			
		}

		protected override string SkinFolder 
		{
			get 
			{
				return "~/Themes/" + ThemeName + "/Skins/FileGalleries/"; 
			}
		}

		protected override string DefaultSkinPath
		{
			get
			{
				return "~/Themes/default/Skins/FileGalleries/" + ExternalSkinFileName;
			}
		}


		public virtual User CurrentUser
		{
			get { return _currentUser; }
		}

		public virtual Folder CurrentFolder
		{
			get
			{
				if(_currentFolder == null)
					if(!Globals.IsNullorEmpty(csContext.ApplicationKey))
						_currentFolder = Folders.GetFolder( csContext.ApplicationKey );
					else if (csContext.SectionID != -1)
						_currentFolder = Folders.GetFolder(csContext.SectionID);

				return _currentFolder;
			}
		}

		public virtual PostCategory CurrentCategory
		{
			get
			{
				if(_currentCategory == null)
					if(csContext.CategoryID != -1)
						_currentCategory = PostCategories.GetCategory(csContext.CategoryID, CurrentFolder.SectionID, CurrentUser.IsFileAdministrator);
				return _currentCategory;
			}
		}
	
		public virtual Entry CurrentEntry
		{
			get
			{
				if(_currentEntry == null)
					if(csContext.PostID != -1)
						_currentEntry = Entries.GetEntry(CurrentFolder.SectionID, csContext.PostID);
				return _currentEntry;
			}
		}
	}
}
